<?php
namespace App\Providers\VersionTraits;

use App\Models\Shop\WxShopService;
use App\Wen\Utils\Settings;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Dcat\Admin\Models\Menu;

trait _1_0_30_trait{
    function _v1_0_21(){
        if(!Menu::where('uri', '/settings/ad')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  12;
            $admin_menu->title = '广告';
            $admin_menu->uri = '/settings/ad';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
    }
    function _v1_0_21_1(){
        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_content'){
                $col_type = $column->Type;
                if($col_type == 'text'){
                    Schema::table('wx_posts', function (Blueprint $table) {
                        $table->longText('posts_content')->change();
                    });
                }
                break;
            }
        }

    }
    function _v1_0_21_3(){
        if(!Menu::where('uri', '/settings/pagemine')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  13;
            $admin_menu->title = '我的';
            $admin_menu->uri = '/settings/pagemine';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_slideshow'));
        foreach($table_info_columns as $column){
            if($column->Field == 'target_id'){
                $col_type = $column->Type;
                if($col_type == 'bigint(20)'){
                    Schema::table('wx_slideshow', function (Blueprint $table) {
                        $table->string('target_id', 255)->change();
                    });
                }
                break;
            }
        }
    }
    function _v1_0_21_10(){
        if(Menu::where('uri', '/settings/hot')->exists()){
            Menu::where('uri', '/settings/hot')->delete();
        }
    }

    function _v1_0_21_11(){
        if(!Schema::hasColumn('wx_shop_classify', 'in_mp')){
            Schema::table('wx_shop_classify', function (Blueprint $table) {
                // （0：不展示，1：总是展示 2：审核时不展示）
                $table->tinyInteger('in_h5')->default(1)->after('state')->comment('h5');
                $table->tinyInteger('in_app')->default(1)->after('state')->comment('app');
                $table->tinyInteger('in_mp')->default(1)->after('state')->comment('小程序');
            });
        }
    }

    function _v1_0_21_12(){
        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_circle'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_circle', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
                break;
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_comment'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'posts_user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment', function (Blueprint $table) {
                        $table->bigInteger('posts_user_id')->change();
                    });
                }
            }else if($column->Field == 'comment_agent_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment', function (Blueprint $table) {
                        $table->bigInteger('comment_agent_id')->change();
                    });
                }
            }else if($column->Field == 'comment_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment', function (Blueprint $table) {
                        $table->bigInteger('comment_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_comment_like'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment_like', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'comment_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment_like', function (Blueprint $table) {
                        $table->bigInteger('comment_id')->change();
                    });
                }
            }else if($column->Field == 'comment_user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_comment_like', function (Blueprint $table) {
                        $table->bigInteger('comment_user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_chat'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_chat', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'object_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_chat', function (Blueprint $table) {
                        $table->bigInteger('object_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_collect'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_collect', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'posts_user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_collect', function (Blueprint $table) {
                        $table->bigInteger('posts_user_id')->change();
                    });
                }
            }else if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_collect', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_feedback'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_feedback', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_forward'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_forward', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'posts_user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_forward', function (Blueprint $table) {
                        $table->bigInteger('posts_user_id')->change();
                    });
                }
            }else if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_forward', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_like'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_like', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'posts_user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_like', function (Blueprint $table) {
                        $table->bigInteger('posts_user_id')->change();
                    });
                }
            }else if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_like', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_notice'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_notice', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_notice', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'circle_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts', function (Blueprint $table) {
                        $table->bigInteger('circle_id')->change();
                    });
                }
            }else if($column->Field == 'address_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts', function (Blueprint $table) {
                        $table->bigInteger('address_id')->change();
                    });
                }
            }else if($column->Field == 'tags_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts', function (Blueprint $table) {
                        $table->bigInteger('tags_id')->change();
                    });
                }
            }
        }


        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts_goods'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_goods', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'goods_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_goods', function (Blueprint $table) {
                        $table->bigInteger('goods_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts_img'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_img', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_img', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts_tags'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_tags', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'tags_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_tags', function (Blueprint $table) {
                        $table->bigInteger('tags_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts_video'));
        foreach($table_info_columns as $column){
            if($column->Field == 'posts_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_video', function (Blueprint $table) {
                        $table->bigInteger('posts_id')->change();
                    });
                }
            }else if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_posts_video', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_refund'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_refund', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'order_good_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_refund', function (Blueprint $table) {
                        $table->bigInteger('order_good_id')->change();
                    });
                }
            }else if($column->Field == 'order_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_refund', function (Blueprint $table) {
                        $table->bigInteger('order_id')->change();
                    });
                }
            }else if($column->Field == 'goods_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_refund', function (Blueprint $table) {
                        $table->bigInteger('goods_id')->change();
                    });
                }
            }else if($column->Field == 'product_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_refund', function (Blueprint $table) {
                        $table->bigInteger('product_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_search'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_search', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_shop_cart'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_cart', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'goods_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_cart', function (Blueprint $table) {
                        $table->bigInteger('goods_id')->change();
                    });
                }
            }else if($column->Field == 'product_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_cart', function (Blueprint $table) {
                        $table->bigInteger('product_id')->change();
                    });
                }
            }
        }


        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_shop_goods_product'));
        foreach($table_info_columns as $column){
            if($column->Field == 'goods_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_goods_product', function (Blueprint $table) {
                        $table->bigInteger('goods_id')->change();
                    });
                }
            }
        }


        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_shop_order'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_order', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_shop_order_after'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_order_after', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_shop_order_goods'));
        foreach($table_info_columns as $column){
            if($column->Field == 'order_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                        $table->bigInteger('order_id')->change();
                    });
                }
            }else if($column->Field == 'goods_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                        $table->bigInteger('goods_id')->change();
                    });
                }
            }else if($column->Field == 'product_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                        $table->bigInteger('product_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_user'));
        foreach($table_info_columns as $column){
            if($column->Field == 'authentication_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user', function (Blueprint $table) {
                        $table->bigInteger('authentication_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_user_circle'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_circle', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'circle_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_circle', function (Blueprint $table) {
                        $table->bigInteger('circle_id')->change();
                    });
                }
            }else if($column->Field == 'product_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_circle', function (Blueprint $table) {
                        $table->bigInteger('product_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_user_follow'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_follow', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'user_follow_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_follow', function (Blueprint $table) {
                        $table->bigInteger('user_follow_id')->change();
                    });
                }
            }
        }

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_user_plate'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_plate', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }else if($column->Field == 'plate_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_user_plate', function (Blueprint $table) {
                        $table->bigInteger('plate_id')->change();
                    });
                }
            }
        }

    }

    function _v1_0_21_13(){
        if(!Schema::hasColumn('wx_user', 'country_code')){
            Schema::table('wx_user', function (Blueprint $table) {
                // （0：不展示，1：总是展示 2：审核时不展示）
                $table->string('country_code', 25)->nullable()->after('phone')->comment('国家区号');
                $table->unique(['phone', 'country_code'], 'index_19');
            });
        }
    }
    function _v1_0_22_1(){
        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_authentication'));
        foreach($table_info_columns as $column){
            if($column->Field == 'user_id'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_authentication', function (Blueprint $table) {
                        $table->bigInteger('user_id')->change();
                    });
                }
            }
        }
    }


    function _v1_0_22_2(){

        if(!Schema::hasColumn('wx_circle', 'is_follow_vip')){
            Schema::table('wx_circle', function (Blueprint $table) {

                $table->tinyInteger('publish_pay_credit')->default(0)->after('is_hot')->comment('0：金币 1：余额');
                $table->float('publish_pay_num')->default(0)->after('is_hot')->comment('付费发布单价');
                $table->tinyInteger('is_publish_pay')->default(0)->after('is_hot')->comment('付费发布/次');
                $table->tinyInteger('is_publish_admin')->default(0)->after('is_hot')->comment('发布需管理员');
                $table->tinyInteger('is_publish_authentication')->default(0)->after('is_hot')->comment('发布需认证');
                $table->tinyInteger('is_publish_vip')->default(0)->after('is_hot')->comment('发布需VIP');
                $table->tinyInteger('is_publish_follow')->default(0)->after('is_hot')->comment('发布需关注');

                $table->integer('follow_pay_duration')->default(0)->after('is_hot')->comment('关注付费时长');
                $table->tinyInteger('follow_pay_credit')->default(0)->after('is_hot')->comment('0：金币 1：余额');
                $table->float('follow_pay_num')->default(0)->after('is_hot')->comment('关注付费数额');
                $table->tinyInteger('is_follow_pay')->default(0)->after('is_hot')->comment('关注需付费');
                $table->tinyInteger('is_follow_admin')->default(0)->after('is_hot')->comment('关注需管理员');
                $table->tinyInteger('is_follow_authentication')->default(0)->after('is_hot')->comment('关注需认证');
                $table->tinyInteger('is_follow_vip')->default(0)->after('is_hot')->comment('关注需VIP');


                $table->float('circle_user_paycontent_division')->default(0)->after('user_id')->comment('圈主付费贴分成');
                $table->float('circle_user_division')->default(0)->after('user_id')->comment('圈主其他分成');
            });
        }
    }


    function _v1_0_22_3(){
        if(!Menu::where('uri', '/settings/pagevip')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  14;
            $admin_menu->title = '会员';
            $admin_menu->uri = '/settings/pagevip';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
        if(!Menu::where('uri', '/settings/coin')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  15;
            $admin_menu->title = '金币';
            $admin_menu->uri = '/settings/coin';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
    }

    function _v1_0_22_4(){
        if(!Schema::hasColumn('wx_minicode', 'user_id')){
            Schema::table('wx_minicode', function (Blueprint $table) {
                // （0：不展示，1：总是展示 2：审核时不展示）
                $table->bigInteger('user_id')->default(0)->after('scene')->comment('用户id');
            });
        }

        if(!Schema::hasColumn('wx_user', 'who')){
            Schema::table('wx_user', function (Blueprint $table) {
                // （0：不展示，1：总是展示 2：审核时不展示）
                $table->bigInteger('who')->default(0)->after('gender')->index('index_20')->comment('邀请人');
            });
        }

        if(!Schema::hasTable('wx_user_invite_benefit_record')){
            Schema::create('wx_user_invite_benefit_record', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->index('index_0')->comment('用户id');
                $table->bigInteger('order_id')->default(0)->comment('订单id');
                $table->bigInteger('shop_order_id')->default(0)->comment('商品订单id');
                $table->decimal('order_price')->default(0)->comment('订单金额');
                $table->bigInteger('lv1_user')->default(0)->index('index_1')->comment('一层上级id');
                $table->decimal('lv1_benefit')->default(0)->comment('一级用户收益');
                $table->bigInteger('lv2_user')->default(0)->index('index_2')->comment('二层上级id');
                $table->decimal('lv2_benefit')->default(0)->comment('二级用户收益');
                $table->bigInteger('lv3_user')->default(0)->index('index_3')->comment('三层上级id');
                $table->decimal('lv3_benefit')->default(0)->comment('三级用户收益');
                $table->timestamps();
            });
        }


        if(!Schema::hasColumn('wx_shop_goods', 'download_version')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                // （0：不展示，1：总是展示 2：审核时不展示）
                $table->string('download_version')->nullable()->default('')->after('url')->comment('当前版本');
                $table->string('download_url')->nullable()->default('')->after('url')->comment('下载url');
                $table->bigInteger('question_id')->nullable()->default(0)->after('url')->comment('帮助问题ID');
                $table->integer('can_purchase_times')->nullable()->default(0)->after('url')->comment('限购次数，0：无限制');
            });
        }

        if(_empty_(Settings::get('app_index_tab', ''))){
            Settings::set('app_index_tab', '[{"plate_name":"\u5173\u6ce8","type":"0","target_type":"0","target":null},{"plate_name":"\u63a8\u8350","type":"1","target_type":"0","target":null},{"plate_name":"\u70ed\u95e8","type":"2","target_type":"0","target":null}]');
        }


        if(!Schema::hasColumn('wx_shop_order_goods', 'download_version')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                // （0：不展示，1：总是展示 2：审核时不展示）
                $table->string('download_version')->nullable()->default('')->after('paid_content')->comment('当前下载版本');
                $table->string('download_url')->nullable()->default('')->after('paid_content')->comment('当前下载url');
            });
        }

    }

    function _v1_0_22_5(){
        if(!Schema::hasTable('wx_user_experience')){
            Schema::create('wx_user_experience', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->tinyInteger('type')->comment('经验类型');
                $table->integer('num')->comment('增加经验值');
                $table->timestamps();
                $table->index(['user_id', 'type'], 'index_0');
            });
        }

        if(!Schema::hasColumn('wx_user', 'black_reason')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('black_reason')->nullable()->after('user_state')->comment('拉黑原因');
            });
        }

    }

    function _v1_0_22_7(){
        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_user_financial_record'));
        foreach($table_info_columns as $column){
            if($column->Field == 'num'){
                $col_type = $column->Type;
                if($col_type == 'bigint(20)'){
                    Schema::table('wx_user_financial_record', function (Blueprint $table) {
                        $table->float('num')->change();
                    });
                }
            }
        }
        if(!Schema::hasColumn('wx_shop_order_goods', 'refund_deadline')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                $table->timestamp('refund_deadline')->nullable()->after('state')->comment('退款截止时间');
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'coins_num')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->float('coins_pay')->default(0)->after('serial_number')->comment('金币抵扣￥');
                $table->bigInteger('coins_num')->default(0)->after('serial_number')->comment('使用金币');
            });
        }

        if(!Schema::hasColumn('wx_shop_order_goods', 'goods_type')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                $table->tinyInteger('goods_type')->default(0)->after('goods_id')->comment('商品类型');
            });
        }

        if(!Schema::hasColumn('wx_user_coin_record', 'type')){
            Schema::table('wx_user_coin_record', function (Blueprint $table) {
                $table->tinyInteger('type')->default(0)->after('user_id')->comment('变更类型');
            });
        }
    }

    function _v1_0_22_8(){
        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_shop_order_goods'));
        foreach($table_info_columns as $column){
            if($column->Field == 'recharge'){
                $col_type = $column->Type;
                if($col_type == 'int(11)'){
                    Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                        $table->float('recharge')->change();
                    });
                }
            }
        }
    }

    function _v1_0_22_10(){
        if(!Menu::where('uri', '/settings/emoji')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  16;
            $admin_menu->title = '表情';
            $admin_menu->uri = '/settings/emoji';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasColumn('wx_chat', 'chat_audio_url')){
            Schema::table('wx_chat', function (Blueprint $table) {
                $table->integer('chat_audio_length')->default(0)->after('chat_image')->comment('聊天音频时长');
                $table->string('chat_audio_url')->nullable()->after('chat_image')->comment('聊天音频');
            });
        }

    }

    function _v1_0_23(){
        if(!Menu::where('uri', '/settings/pagenotice')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  18;
            $admin_menu->title = '消息';
            $admin_menu->uri = '/settings/pagenotice';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    function _v1_0_24_3(){

        if(!Schema::hasColumn('wx_posts_img', 'width')){
            Schema::table('wx_posts_img', function (Blueprint $table) {
                $table->integer('height')->default(0)->after('img_url')->comment('图片高度');
                $table->integer('width')->default(0)->after('img_url')->comment('图片宽度');
            });
        }
    }

    function _v1_0_24_4(){
        if( !(Settings::get('menu_invite_benefit_parent_id', 0) > 0) && !(Menu::where('title', '分享裂变')->exists()) ){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-fort-awesome';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  49;
            $admin_menu->title = '分享裂变';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_invite_benefit_parent_id', $parent_id);

            if(!Menu::where('uri', '/invite_benefit/config')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  1;
                $admin_menu->title = '配置';
                $admin_menu->uri = '/invite_benefit/config';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/invite_benefit/record')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  1;
                $admin_menu->title = '记录';
                $admin_menu->uri = '/invite_benefit/record';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }
    }

    function _v1_0_24_7(){
        if(!Schema::hasTable('wx_circle_tag')){
            Schema::create('wx_circle_tag', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('circle_id')->comment('圈子id');
                $table->bigInteger('tag_id')->comment('话题id');
                $table->bigInteger('times')->comment('次数');
                $table->unique(['circle_id', 'tag_id'], 'index_1');
                $table->timestamps();
            });
        }
    }


    function _v1_0_25_1(){
        if(!Schema::hasTable('wx_user_avatar_frame')){
            Schema::create('wx_user_avatar_frame', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->string('image_url')->comment('图像地址');
                // （0：通用，1：会员 2：金币 3：余额）
                $table->unsignedTinyInteger('type')->default(0)->comment('类型');
                $table->unsignedFloat('price')->default(0)->comment('价格');
                $table->string('description', 255)->nullable()->comment('描述');
                $table->unsignedInteger('quantity')->default(999999)->comment('数量');
                $table->unsignedTinyInteger('status')->default(0)->comment('状态（0：正常，1：下架）');
                $table->timestamps();
            });
        }
        if(!Schema::hasTable('wx_user_avatar_frame_purchase')){
            Schema::create('wx_user_avatar_frame_purchase', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->index('index_0')->comment('用户id');
                $table->bigInteger('avatar_frame_id')->index('index_1')->comment('头像框id');
                // 会员解锁，金币解锁，余额解锁，活动解锁
                $table->unsignedTinyInteger('purchase_way')->comment('解锁方式');
                $table->unsignedTinyInteger('credit_type')->default(0)->comment('0：金币 1：余额');
                $table->unsignedFloat('price')->default(0)->comment('解锁时价格');
                $table->bigInteger('activity_id')->default(0)->comment('解锁活动id');
                $table->string('description', 255)->nullable()->comment('说明');
                $table->timestamps();
            });
        }
        if( !(Settings::get('menu_user_avatar_frame_parent_id', 0) > 0) && !(Menu::where('title', '头像框')->exists()) ){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-tripadvisor';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  49;
            $admin_menu->title = '头像框';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_user_avatar_frame_parent_id', $parent_id);

            if(!Menu::where('uri', '/avatar_frame/config')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  0;
                $admin_menu->title = '配置';
                $admin_menu->uri = '/avatar_frame/config';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/avatar_frame/frame')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  1;
                $admin_menu->title = '头像框';
                $admin_menu->uri = '/avatar_frame/frame';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/avatar_frame/purchase')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  2;
                $admin_menu->title = '购买记录';
                $admin_menu->uri = '/avatar_frame/purchase';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }
    }

}
